---
id: indexing
title: Indexing functions
sidebar_label: Indexing
slug: /api/indexing
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

These functions are used for finding the H3 cell index containing coordinates, and for finding the center and boundary of H3 indexes.

## latLngToCell

<Tabs
  groupId="language"
  defaultValue="c"
  values={[
    {label: 'C', value: 'c'},
    {label: 'Python', value: 'python'},
    {label: 'Java', value: 'java'},
    {label: 'JavaScript (Live)', value: 'javascript'},
  ]
}>
<TabItem value="c">

```c
H3Error latLngToCell(const LatLng *g, int res, H3Index *out);
```

</TabItem>
<TabItem value="python">

```py
h3.latlng_to_cell(lat, lng, resolution)
```

</TabItem>
<TabItem value="java">

```java
long latLngToCell(double lat, double lng, int res);
String latLngToCellAddress(double lat, double lng, int res);
```

</TabItem>
<TabItem value="javascript">

```js
h3.latLngToCell(lat, lng, res)
```

```js live
function example() {
  const lat = 45;
  const lng = 40;
  const res = 2;
  return h3.latLngToCell(lat, lng, res);
}
```

</TabItem>
</Tabs>

Indexes the location at the specified resolution, returning the index of the cell containing the location.

Returns 0 (`E_SUCCESS`) on success.

## cellToLatLng

<Tabs
  groupId="language"
  defaultValue="c"
  values={[
    {label: 'C', value: 'c'},
    {label: 'Python', value: 'python'},
    {label: 'Java', value: 'java'},
    {label: 'JavaScript (Live)', value: 'javascript'},
  ]
}>
<TabItem value="c">

```c
H3Error cellToLatLng(H3Index cell, LatLng *g);
```

</TabItem>
<TabItem value="python">

```py
h3.cell_to_latlng(cell)
```

</TabItem>
<TabItem value="java">

```java
LatLng cellToLatLng(long cell);
LatLng cellToLatLng(String cellAddress);
```

</TabItem>
<TabItem value="javascript">

```js
h3.cellToLatLng(cell)
```

```js live
function example() {
  const cell = '85283473fffffff';
  return h3.cellToLatLng(cell);
}
```

</TabItem>
</Tabs>

Finds the centroid of the cell.

Returns 0 (`E_SUCCESS`) on success.

## cellToBoundary

<Tabs
  groupId="language"
  defaultValue="c"
  values={[
    {label: 'C', value: 'c'},
    {label: 'Python', value: 'python'},
    {label: 'Java', value: 'java'},
    {label: 'JavaScript (Live)', value: 'javascript'},
  ]
}>
<TabItem value="c">

```c
H3Error cellToBoundary(H3Index cell, CellBoundary *bndry);
```

</TabItem>
<TabItem value="python">

```py
h3.cell_to_boundary(cell, geo_json=False)
```

</TabItem>
<TabItem value="java">

```java
List<LatLng> cellToBoundary(long cell);
List<LatLng> cellToBoundary(String cellAddress);
```

</TabItem>
<TabItem value="javascript">

```js
h3.cellToBoundary(cell, [formatAsGeoJson])
```

```js live
function example() {
  const cell = '85283473fffffff';
  return h3.cellToBoundary(cell);
}
```

</TabItem>
</Tabs>

Finds the boundary of the cell.

Returns 0 (`E_SUCCESS`) on success.
